/**
 * @file 2022/i/main
 * @brief
 * @see
 * @author Ruiming Guo (guoruiming@stu.scu.edu.cn)
 * @copyright 2022
 * @date 5/20/2022 16:28:44
 **/

#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
const int INF = 0x3f3f3f3f;
const ll LLINF = 0x3f3f3f3f3f3f3f3f;
const int N = INF;
int main() {
  // High rating and good luck!
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  int tc;
  cin >> tc;
  while (tc--) {
    ll x, y, z;
    cin >> x >> y >> z;
    ll k = (y - x) / z;
    for (int p = 1; p < 16; ++p) {
      for (int i = 0; i < k; ++i) {
        x += k * z;
      }
    }
    for (int p = 16; p <= 32; ++p) {
    }
  }
  return 0;
}
